package com.cxy.datawarehouse.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.cxy.datawarehouse.entity.User;
import com.cxy.datawarehouse.exception.BizException;

public class TokenUtils {

    public static String setUserToken(User user) {
        String uuid = UUIDUtils.getUuid();
        String jsonStr = JSONUtil.toJsonStr(user);
        RedisUtils.set(uuid, jsonStr);
        return uuid;
    }


    public static User getUserSession(String token) {
        String s = RedisUtils.get(token);
        if (StrUtil.isBlank(s)) {
            throw new BizException("未登录或登录超时");
        }
        return JSONUtil.toBean(s, User.class);
    }

    public static void deleteUserSession(String token){
        RedisUtils.delete(token);
    }
}
